﻿//Copyright (c) Microsoft Corporation. All rights reserved.

using System;

namespace Microsoft.Ted.Wacel.TestConsole
{
    public class VisualTester
    {
        public static int AssertCounter { get; set; }
        public static int SuccessCounter { get; set; }
        #region Null checks
        public static void IsNotNull(object actual)
        {
            Assert(actual != null, "Object is null.");
        }
        public static void IsNull(object actual)
        {
            Assert(actual == null, "Object is null.");
        }
        #endregion
        #region Equal checks
        public static void AreEqual(int expected, int actual)
        {
            Assert(expected == actual, string.Format("Expected <{0}>. Actual <{1}>.",
                                                    expected, actual));
        }
        public static void AreEqual(string expected, string actual)
        {
            Assert(expected == actual, string.Format("Expected <{0}>. Actual <{1}>.",
                                                    expected, actual));
        }
        public static void AreEqual(double expected, double actual)
        {
            Assert(expected == actual, string.Format("Expected <{0}>. Actual <{1}>.",
                                                    expected, actual));
        }
        public static void AreEqual(object expected, object actual)
        {
            Assert(expected == actual, string.Format("Expected <{0}>. Actual <{1}>.",
                                                    expected, actual));
        }
        public static void AreEqual(long expected, long actual)
        {
            Assert(expected == actual, string.Format("Expected <{0}>. Actual <{1}>.",
                                                    expected, actual));
        }
        #endregion
        public static void Assert(bool expression, string message)
        {
            var oldColor = Console.ForegroundColor;

            AssertCounter++;
            if (expression)
                SuccessCounter++;

            if (!expression)
                printLine(ConsoleColor.Red, message);
            else
                printLine(ConsoleColor.Green, "OK");

            Console.ForegroundColor = oldColor;
        }
        public static void Assert(bool expression)
        {
            Assert(expression, "FAIL");
        }
        private static void printLine(ConsoleColor color, string text)
        {
            Console.ForegroundColor = color;
            Console.WriteLine(" Assertion #" + AssertCounter.ToString("00") + ": " + text);
        }
    }
}
